import sys
sys.path.append('..\\..')
from Djoser import *

root = Tk()
main = DjWindow(root)
f1 = Frame(main.basecontrol)
f1.pack()

#Create a new window
otherwindow = DjWindow(root, True) 
otherwindow.title = 'Hello'
Button(otherwindow.basecontrol,text='hi').place(x=1,y=1)

def test(w, n):
	if n==1:
		w.enabled = True
		assert w.enabled==True
		w.enabled = False
		assert w.enabled==False
	elif n==2: 
		w.transparency = 0.5
		assert w.transparency == 0.5
	elif n==3:
		w.title = 'changed'
		assert w.title == 'changed'
	elif n==4: w.bgcolor = (0,0,100)
	elif n==5: 
		w.borderwidth = 4
		assert w.borderwidth == 4
		w.borderstyle = 'raised'
		assert w.borderstyle == 'raised'
	elif n==6:
		w.width = 500
		w.height = 400
		assert w.width == 500 and w.height == 400
		# Note that if the pack method is used, though, it will go back...
	elif n==7:
		w.cursor = 'hand2'
		assert w.cursor == 'hand2'
	elif n==8:
		w.topmost = False
		assert w.topmost==False
		w.topmost = True
		assert w.topmost == True
	elif n==9:
		print 'Now, if the border width is 4, you can\'t close it'
		def onclose(w=w): 
			print 'onclose'
			if w.borderwidth==4: return False
		def onfocus(): print 'onfocus' #Apparently doesn't work in Windows.
		w.onclose = onclose
		w.onfocus = onfocus
	elif n==12:
		w.set_rect(0,0,200,300)
		w.basecontrol.update_idletasks()
		print w.get_rect()
	elif n==20:
		# Read  http://effbot.org/tkinterbook/tkinter-dialog-windows.htm
		ww = DjWindow(root, True) 
		def chooseone(ww=ww):
			ww._result = 1
			ww.quit()
		def choosetwo(ww=ww):
			ww._result = 2
			ww.quit()
		def onclose(ww=ww): 
			ww._result = 0
			ww.quit()
			# It is necessary to call quit(), because calling destroy(), which is done automatically by the wrapper, is not enough
		Button(ww.basecontrol,text='1',command=chooseone).pack()
		Button(ww.basecontrol,text='2',command=choosetwo).pack()
		ww.onclose = onclose
		ww.set_style('dialog')
		ww.run_dialog()
		print 'you chose',ww._result
	elif n==30:
		import sys
		if sys.platform=='win32': w.set_icon(r'icon.ico')


Button(f1, text='disable',command=lambda:test(otherwindow,1)).pack(side=LEFT)
Button(f1, text='transparent',command=lambda:test(otherwindow,2)).pack(side=LEFT)
Button(f1, text='title',command=lambda:test(otherwindow,3)).pack(side=LEFT)
Button(f1, text='color',command=lambda:test(otherwindow,4)).pack(side=LEFT)
Button(f1, text='borders',command=lambda:test(otherwindow,5)).pack(side=LEFT)
Button(f1, text='size',command=lambda:test(otherwindow,6)).pack(side=LEFT)
Button(f1, text='cursor',command=lambda:test(otherwindow,7)).pack(side=LEFT)
Button(f1, text='top',command=lambda:test(otherwindow,8)).pack(side=LEFT)
Button(f1, text='events',command=lambda:test(otherwindow,9)).pack(side=LEFT)

f2 = Frame(main.basecontrol)
f2.pack()
Button(f2, text='ratio',command=lambda:otherwindow.basecontrol.aspect(1,20,1,21)).pack(side=LEFT) #Apparently doesn't work in Windows.
Button(f2, text='tool',command=lambda:otherwindow.set_style('tool')).pack(side=LEFT)
Button(f2, text='dialog',command=lambda:otherwindow.set_style('dialog')).pack(side=LEFT)
Button(f2, text='bare',command=lambda:otherwindow.set_style('bare')).pack(side=LEFT)
Button(f2, text='setrect',command=lambda:test(otherwindow,12)).pack(side=LEFT)
Button(f2, text='noresizey',command=lambda:otherwindow.set_resizeable(False,True)).pack(side=LEFT)
Button(f2, text='noresize',command=lambda:otherwindow.set_resizeable(False,False)).pack(side=LEFT)
Button(f2, text='sizelimits',command=lambda:otherwindow.set_size_limits(200,210,200,250)).pack(side=LEFT)
Button(f2, text='RUNDIALOG',command=lambda:test(otherwindow,20)).pack(side=LEFT)

f3 = Frame(main.basecontrol)
f3.pack()
Button(f3, text='hide',command=lambda:otherwindow.hide()).pack(side=LEFT)
Button(f3, text='show',command=lambda:otherwindow.show()).pack(side=LEFT)
Button(f3, text='minimize',command=lambda:otherwindow.minimize()).pack(side=LEFT)
Button(f3, text='Icon',command=lambda:test(otherwindow,30)).pack(side=LEFT)

	
root.mainloop()
